package com.bdrm.controller.user;

import com.bdrm.dto.OrdersSubmitDTO;
import com.bdrm.entity.Orders;
import com.bdrm.result.PageResult;
import com.bdrm.result.Result;
import com.bdrm.service.OrderService;
import com.bdrm.vo.OrderInfoVO;
import com.bdrm.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("userOrderController")
@RequestMapping("/user/order")
@Api(tags = "用户端订单相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        log.info("下单传来的数据：{}",ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO =orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    @ApiOperation("支付成功后的修改订单状态")
    @PutMapping("/status/{orderNumber}")
    public Result updateStatus(@PathVariable String orderNumber) {
        log.info("订单号：{}",orderNumber);
        orderService.update(orderNumber);
        return Result.success();
    }

    @ApiOperation("根据订单号查询数据")
    @GetMapping("/query/{id}")
    public Result<OrderInfoVO> query(@PathVariable Long id) {
        log.info("订单号：{}",id);
        OrderInfoVO orders = orderService.detail(id);
        return Result.success(orders);
    }

    @ApiOperation("再来一单")
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id) {
        log.info("订单号：{}",id);
        orderService.repetition(id);
        return Result.success();
    }

    @ApiOperation("分页查询历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> page(Integer page, Integer pageSize,Integer status){
        log.info("分页查询历史订单：{},{},{}",page,pageSize,status);
        PageResult pageResult=orderService.pageQuery(page,pageSize,status);
        return Result.success(pageResult);
    }
}
